package com.hrbu.springboot04.utils;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description:
 * @Author: tanyajun
 * @CreateTime: 2021/4/8
 * @Blog: https://tanyajun.top
 */
public class UploadFileUtil {
    public static File mkdirsByDate(String root){
        if(root==null||"".equals(root)){
            root="E:/uploads";
        }
        SimpleDateFormat format = new SimpleDateFormat("YYYY/MM/dd");
        String childPath = format.format(new Date());
        String path=root+"/"+childPath;
        File file = new File(path);
        return file;
    }
    public static String generateOriginalFilename(String originalFilename){
        if(originalFilename==null||"".equals(originalFilename)){
            return "NULL_NAME_"+System.currentTimeMillis();
        }
        String newName=originalFilename.substring(0,originalFilename.lastIndexOf("."))+"_"+
                System.currentTimeMillis()+
                originalFilename.substring(originalFilename.lastIndexOf("."));
        return newName;
    }
}
